<?php 
$_helper = $this->helper('catalog/output');
$allIds = $this->getAllIds();
$zgbHelper = Mage::helper('zgb');
?>
<div class="pre-brands" style="display:none;">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('category_product_brands')->toHtml(); ?>
</div>
<div class="category-product">
<?php foreach($allIds as $bId => $cId): ?>
	<?php $products = $this->getCategoryProducts($cId); ?>
<div>
	<div class="product-header">
		<h3><a href="<?php echo $this->getCategoryUrl($cId) ?>"><?php echo $this->getCategoryName($cId); ?></a></h3>
		<p class="msg-content msg-content-<?php echo $cId; ?>"></p><a href="<?php echo $this->getCategoryUrl($cId) ?>" class="more-cat">更多></a>
	</div>
	<div class="product-content clearfix">
		<div class="pleft left">
			<?php echo $this->getLayout()->createBlock('bannerslider/default')->setTemplate('bannerslider/slider7.phtml')->setBannersliderId($bId)->toHtml(); ?>
			<div class="product-brands">
				<h3>热门品牌</h3>
				<ul class="brand-content brand-content-<?php echo $cId; ?> clearfix"></ul>
			</div>
		</div>
		<div class="pright right">
	<?php
		/*$array = array();
		foreach($query as $q){
			$array[] = $q['product_id'];
		}

		$_productCollection = Mage::getModel('catalog/category')->load($cId)
				->getProductCollection()
				->addAttributeToSelect('*')
			    ->addAttributeToFilter('status', 1)
			    ->addAttributeToFilter('visibility', 4)
			    ->addAttributeToFilter('entity_id',array('in'=>$array));

			Mage::getSingleton('cataloginventory/stock')
    			->addInStockFilterToCollection($_productCollection);

    	$count = $_productCollection->count();
    	$pids = $_productCollection->getAllIds();

    	if($count > 10){
    		$pids = array_slice($pids, 0, 10);
    	}

		if($count < 10){
			$productCollection = Mage::getModel('catalog/category')->load($cId)
				->getProductCollection()
				->addAttributeToSelect('*')
			    ->addAttributeToFilter('status', 1)
			    ->addAttributeToFilter('visibility', 4)
			    ->addAttributeToFilter('entity_id',array('nin'=>$array));

			Mage::getSingleton('cataloginventory/stock')
    			->addInStockFilterToCollection($productCollection);

			$productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));

			$productCollection->distinct('entity_id');
			$productCollection->setPage(1, 10-$count);

			foreach($productCollection as $product){
				$pids[] = $product->getId();
			}
		}*/
	?>
	<?php $i = 0; foreach($products as $_product): ?>
		<?php //$_product = Mage::getModel('catalog/product')->load($id); ?>
				<?php if($i%5 == 0): ?>
			<ul class="clearfix">
				<?php endif; ?>
				<li class="left">
		            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
		                <div class="wrap">
		                    <div class="product-image">

		                        <img src="<?php echo $this->getSkinUrl('images/loading.gif') ?>" data-original="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(150); ?>" width="150" height="150" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
		                        <?php if($zgbHelper->hasTag($_product)): ?>
		                        	<div class="product-sale-tag">
		                        		<img src="<?php echo $zgbHelper->getSaleTagUrl($_product, $this->getSkinUrl('images')); ?>" alt="" />
		                        	</div>
		                        <?php endif; ?>
		                    </div>
		                    <div class="product-shop">
		                            <h3><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h3>
		                            <?php echo $this->getPriceHtml($_product, true) ?>
		                    </div>
		                </div>
		            </a>
		        </li>
		        <?php if($i%5 == 4): ?>
			</ul>
				<?php endif; ?>
			<?php $i++; ?>
			
	<?php endforeach; ?>
			</div>
		</div>
</div>
<script type="text/javascript">
	(function($){
		$(function(){
			$(".brand-content-<?php echo $cId; ?>").html($(".pre-brands .brand-cat-<?php echo $cId ?>").html());
			$(".msg-content-<?php echo $cId; ?>").html($(".pre-brands .cat-msg-<?php echo $cId ?>").html());
		})
	})(jQuery)
</script>
<?php endforeach; ?>
</div>
